package com.adtech.farmProducts.adapter;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;

import com.adtech.common.widgets.recycler.RecyclerViewAdapter;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.model.BillingType;

/**
 * Author:  xiaocz.
 * Date:    2019/05.04.
 * Descr:  计费类型
 */
public class BillingTypeAdapter extends RecyclerViewAdapter<BillingType> {


    private static onClickListener onClickListener;
    public BillingTypeAdapter(AdapterListener<BillingType> adapterListener) {
        super(adapterListener);
    }

    public void setBillingOnClickListener(onClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    @Override
    protected int getItemViewType(int position, BillingType data) {
        return R.layout.item_billing_type;
    }

    @Override
    protected ViewHolder<BillingType> getViewHolder(View view, int viewType) {
        return new CouponsViewHolder(view);
    }

    private static class CouponsViewHolder extends ViewHolder<BillingType> {

        private TextView rbBilling,rb_right;

        /**
         * 构造方法
         *
         * @param itemView
         */
        public CouponsViewHolder(View itemView) {
            super(itemView);
            rbBilling = itemView.findViewById(R.id.rb_billing);
            rb_right=itemView.findViewById(R.id.rb_right);
        }

        @Override
        protected void onBind(final BillingType data, final int position) {
            rbBilling.setText(data.getTempname());
            Drawable rightDrawable;
            if (data.getIsdefault()==1) {
                rightDrawable = mContext.getResources().getDrawable(R.drawable.ic_payment_checked);
            } else {
                rightDrawable = mContext.getResources().getDrawable(R.drawable.ic_payment_unchecked);
            }
            rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
            rbBilling.setCompoundDrawables(rightDrawable, null, null, null);

            rbBilling.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClickButton(1, position, data);
                }
            });
            rb_right.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClickButton(2, position, data);
                }
            });
        }

        @Override
        public boolean isNeedClick() {
            return true;
        }
    }

    public interface onClickListener {
        void onClickButton(int value, int position, BillingType data);
    }
}